<?php
/**
 * Hello Model for Hello World Component
 * 
 * @package    Joomla.Tutorials
 * @subpackage Components
 * @link http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_4
 * @license		GNU/GPL
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.application.component.model');

/**
 * Hello Hello Model
 *
 * @package    Joomla.Tutorials
 * @subpackage Components
 */
class DanhSachModelManage extends JModel
{
	 var $_data; 
	 var $_id;
	 var $_allSinhVien;
	 var $_allNhom;
	 
	/**
	 * Constructor that retrieves the ID from the request
	 *
	 * @access	public
	 * @return	void
	 */
	function __construct()
	{
		parent::__construct();
		
		$array = JRequest::getVar('cid',  0, '', 'array');
		$this->setId((int)$array[0]);
		
		global $mainframe, $option;
		$filter_chuyennganh = $mainframe->getUserStateFromRequest( $option.'filter_chuyennganh', 'filter_chuyennganh', '0', 'string' );
		$filter_nganh= $mainframe->getUserStateFromRequest( $option.'filter_nganh',		'filter_nganh', 		'',			'string' );	
		
		$this->setState('filter_chuyennganh',$filter_chuyennganh);
		$this->setState('filter_nganh',$filter_nganh);
	}

	/**
	 * Method to set the hello identifier
	 *
	 * @access	public
	 * @param	int Hello identifier
	 * @return	void
	 */
	 function _getWhere()
	 {
		$chuyenganh = $this->getState('filter_chuyennganh');
		if($chuyenganh!='')
			$where=" where tenchuyennganh='".$chuyenganh."'";
		return $where;
	 }

	 function getAllSinhVien()
	{
		$nganh = $this->getState('filter_nganh');
		if($nganh!='')
			$where=" where manganh='".$nganh."'";
		
		if (empty( $this->_allSinhVien )) 
		{ 
			$query = " Select * from #__sinh_vien".$where;
			$this->_allSinhVien = $this->_getList( $query ); 
		} 
		return $this->_allSinhVien; 
	}
	
	 function getAllNhom()
	{
		if (empty( $this->_allNhom )) 
		{ 
			$query = " Select * from #__nhom_do_an".$this->_getWhere();
			$this->_allNhom = $this->_getList( $query ); 
		} 
		return $this->_allNhom; 
	}
	
	function setId($id)
	{
		// Set id and wipe data
		$this->_id		= $id;
		$this->_data	= null;
	}

	/**
	 * Method to get a hello
	 * @return object with data
	 */
	function &getData()
	{
		// Load the data
		if (empty( $this->_data )) {
			$query = ' SELECT * FROM #__phan_cong '.
					'  WHERE mapc = '.$this->_id;
			$this->_db->setQuery( $query );
			$this->_data = $this->_db->loadObject();
		}
		if (!$this->_data) {
			$this->_data = new stdClass();
			$this->_data->mads = 0;
			$this->_data->masv = null;
			$this->_data->manhom = null;
		}
		return $this->_data;
	}
}